<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

if (is_cached ('live_comments.php', 240)) $content = file_get_contents ($_SERVER['DOCUMENT_ROOT'].'/include/cache/live_comments.php');
else {
	$content = build_com ();
	cache_file ('live_comments.php', $content);
}

$block = array ();
$block['header'] = $block_header;
$block['name'] = $block_name;
$block['content'] = $content;

Templater::set_var ('block', $block);

($align == 'left')
	? CORE::add_block (Templater::display ('block.tpl'), 'left')
	: CORE::add_block (Templater::display ('block.tpl'), 'right');

function build_com () {
	global $db;
	
	$return = '';
	
	
	$get = $db->query ("SELECT com_id, com_uid, art.art_header, art.art_id, cat.cat_name, cat.cat_header, usr.user_name, usr.user_login FROM ".DB_PEREFIX."_comments AS comm
		LEFT JOIN (SELECT art_id, art_header, art_category FROM ".DB_PEREFIX."_articles) AS art ON comm.com_idi = art.art_id
		LEFT JOIN (SELECT cat_name, cat_header FROM ".DB_PEREFIX."_art_category) AS cat ON art.art_category = cat.cat_name
		LEFT JOIN (SELECT user_id, user_name, user_login FROM ".DB_PEREFIX."_users) AS usr ON comm.com_uid = usr.user_id
		WHERE com_uid != 0 AND com_uid != '' AND com_category = 'articles' ORDER BY com_id DESC LIMIT 0,15");
	
	$return .= '<div id="last_publish">';
	while (list($id, $uid, $art_header, $art_id, $cat_name, $cat_header, $uname, $ulogin) = $db->fetch_row ($get)) {
		
		(!empty($cat_name))
			? $categ = "<a href=\"/articles/$cat_name/\" class=\"cat\">$cat_header</a> / "
			: $categ = '';
		
		$return .= "\n<img src=\"/images/user.gif\" align=\"absmiddle\" style=\"margin-right:5px;\" alt=\"\" /><a href=\"/users/$ulogin\" class=\"user\">$uname</a> &rarr; $categ<a href=\"/articles/$art_id.html#comment$id\" class=\"header\">$art_header</a><br />";
	}
	$return .= '</div>';
	
	return $return;
}
